package com.ymt.bpm.web.rest.mobile;

import com.alibaba.fastjson.JSONObject;
import com.ymt.bpm.service.mobile.MAuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by Johnny on 2017/11/6.
 */
@RestController
@RequestMapping("/mauth")
public class MAuthResource {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MAuthService mas;

    @PostMapping("/login")
    public JSONObject login(@RequestBody Map<String, String> map) {
        String login = map.get("login");
        String password = map.get("password");
        String time = map.get("time");
        if (log.isTraceEnabled()) {
            log.trace("login attemption on mobile: "+ login);
        }
        return mas.login(login, password==null ? "" : password, Long.parseLong(time), mas.getExpiresForMobile());
    }

    @PostMapping("/logindd")
    public JSONObject logindd(@RequestBody Map<String, String> map) {
        String login = map.get("login");
        String authkeydd = map.get("authkeydd");
        String time = map.get("time");
        if (log.isTraceEnabled()) {
            log.trace("logindd attemption on mobile: "+ login);
        }
        return mas.logindd(login, authkeydd, Long.parseLong(time), mas.getExpiresForMobile());
    }

    @PostMapping("/registerdd")
    public JSONObject registerdd(@RequestBody Map<String, String> map) {
        if (log.isTraceEnabled()) {
            log.trace("registerdd attemption on mobile: "+ map);
        }
        return mas.registerdd(map);
    }

}
